package com.exam.controller;

import com.exam.pojo.base.PageResult;
import com.exam.pojo.domain.Question;
import com.exam.pojo.dto.AnswerDTO;
import com.exam.pojo.dto.QuestionDTO;
import com.exam.service.IQuestionService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import lombok.RequiredArgsConstructor;
import org.springframework.web.bind.annotation.*;

import java.util.List;

@RestController
@RequestMapping("/questions")
@Api(tags = "题目相关接口")
@RequiredArgsConstructor
public class QuestionController {

    private final IQuestionService questionService;


    @PostMapping
    @ApiOperation("查询题目列表")
    public PageResult<Question> list(@RequestBody QuestionDTO dto){
        return questionService.list(dto);
    }


    @PostMapping("/submit")
    @ApiOperation("提交题目")
    public void submit(@RequestBody AnswerDTO dto){
        questionService.submit(dto);
    }

    @GetMapping("/easyerr")
    @ApiOperation("查询易错题目列表")
    public List<String> queryEasyerrList(){
        return questionService.queryEasyerrList();
    }


    @GetMapping("/{id}")
    @ApiOperation("根据ID查询")
    public Question getById(@PathVariable Long id){
        return questionService.getById(id);
    }

    @PutMapping
    public void updateQuestion(@RequestBody Question question){
        questionService.updateQuestion(question);
    }
}
